<template>
	<view class="mains box box-tb">
		<u-navbar :is-back="false" :is-fixed="true" title="  " v-if="current == 0 || current ==1"
			:background="background" :border-bottom="false">
			<view class="slot-wrap">
				<view class="ml20" style="color: #fff;">
					五育通劳动教育云
				</view>
			</view>
		</u-navbar>
		<u-navbar :is-back="false" title="我的" title-color="#fff" v-if="current == 2" :background="background"
			:border-bottom="false">
		</u-navbar>

		<view class="content">
			<view class="w100" style="height: 100%;" v-show="current == 0 || current == 1">
				<course-view ref="cousView" :bjmc="bj.bjmc" style="height: 100%;"></course-view>
			</view>
			<view class="w100" v-show="current == 2" style="height: 100%;">
				<person-view ref="personViews" style="height: 100%;"></person-view>
			</view>
		</view>
		<u-tabbar v-model="current" :list="list" @change="goIndex" active-color="#4A8CF5" inactive-color="#646D7E"
			:midButton="true" bg-color="#f1f1fd">
		</u-tabbar>
		<u-popup v-model="show" mode="bottom " border-radius="14rpx" height="648rpx" :safe-area-inset-bottom="true">
			<view class="box box-tb box-align-center box-pack-start title">
				<view class="title-top">
					发布
				</view>
				<view class="box box-align-center box-pack-around pubbar">
					<view class="box box-tb box-align-center box-pack-center" v-for="(item,index) in pubTabbar"
						:key="index" @click="pubTask(index)">
						<u-image :src="item.url" width="96rpx" height="96rpx"></u-image>
						<view class="mt10">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
			<view class="box box-align-center box-pack-around">
				<view class="flex-1" @click="handleCancel()">
					取消
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import courseView from './compoents/index/index.vue';
	import personView from './compoents/person/person.vue';
	export default {
		components: {
			courseView,
			personView
		},
		data() {
			return {
				bj: uni.getStorageSync('clazz'),
				user: uni.getStorageSync("user"),
				pubTabbar: [{
						title: '劳动风采',
						url: '/static/class/icon_class.png'
					},
					{
						title: '实践任务',
						url: 'https://yh-sys.oss-cn-beijing.aliyuncs.com/19346DB96828447E8E98B8C1503A6ACEicon_sj.png?Expires=4799124039&OSSAccessKeyId=LTAI4GL8SwAiLh3sSPXDS7z9&Signature=p58CuMurcrl8ezegUmj4HravE1k%3D'
					}
				],
				list: [{
						text: '首页',
						iconPath: "/static/tabBar/home.png",
						selectedIconPath: "/static/tabBar/home_act.png",
						customIcon: false,
						color: "#646D7E",
						selectedColor: "#4A8CF5"
					},
					{
						iconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						text: '',
						customIcon: true,
						color: "#4A8CF5",
						selectedColor: "#4A8CF5",
						customIcon: true,
						midButton: true
					},
					{
						iconPath: "/static/tabBar/my.png",
						selectedIconPath: "/static/tabBar/my_act.png",
						text: '我的',
						customIcon: false,
						color: "#646D7E",
						selectedColor: "#4A8CF5"
					}
				],
				current: 0,
				background: {
					backgroundColor: '#7484f7'
				},
				show: false,
				invite_cnt: 0,
				currSchool: uni.getStorageSync('currSchool'),
				info: uni.getStorageSync('chat_info')
			}
		},
		onShareAppMessage(res) {
			return {
				title:uni.getStorageSync('fxTitle'),
				path: '/pages/index/share?data=' + encodeURIComponent(JSON.stringify(uni.getStorageSync('chat_info'))),
				imageUrl: uni.getStorageSync('fxImage')
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.cousView.setData();
		},
		onShow() {
			// //console.log(this.bj)
			// this.getClassList();
			if (this.bj == undefined || this.bj == '' || this.bj.id == null) {
				//console.log(">>")
				this.getClassList();
			} else {
				this.$refs.cousView.setData();
			}
			if (this.current == 2) {
				this.$refs.personViews.setdata()
			}
		},
		onLoad: function(options) {
			if (options != undefined) {
				if (options.createclass != undefined) {
					if (options.createclass == 'yes') {
						uni.reLaunch({
							url: '/pages/home/createClass'
						})
					}
				}
			}
			// this.chkClass();
		},
		onPageScroll(res) {
			this.background.backgroundColor = '#7484f7'
			if (res.scrollTop >= 50) {
				this.background.backgroundColor = '#7484f7'
			} else {
				this.background.backgroundColor = '#7484f7'
			}
		},
		onReachBottom(e) {
			this.$refs.cousView.fenye();
		},
		methods: {
			//检查老师是否有班级
			chkClass() {
				//console.log('>>' + this.user.id)
				this.$api.post({
					url: '/dclass/chkclass'
				}, {
					userid: this.user.id
				}).then(res => {
					//console.log(res)
					if (res.classcnt == 0) {
						uni.reLaunch({
							url: '/pages/home/createClass'
						})
					}
				})
			},
			getClassList() {
				this.$api.post({
					url: '/dclass/trClassList'
				}, {
					trid: this.user.id
				}).then(res => {
					//console.log(res)
					if (res.list.length == 0) {
						//创建班级
						//console.log('>>create class')
						uni.reLaunch({
							url: '/pages/home/createClass'
						})
					} else {
						// 设置默认班级
						uni.setStorage({
							key: 'clazz',
							data: res.list[0],
							success: (resp) => {
								this.bj = res.list[0];
								this.$refs.cousView.setData();
							}
						})
					}
				})
			},
			goIndex(i) {
				wx.vibrateShort();
				if (i == 0) {
					uni.setNavigationBarTitle({
						title: '首页'
					});
				} else if (i == 1) {
					this.show = true
				} else {
					this.$nextTick(() => {
						this.$refs.personViews.setdata()
					})
					uni.setNavigationBarTitle({
						title: '我的'
					});
				}
			},
			//切换班级
			goClass() {
				uni.navigateTo({
					url: "/pageHome/changeClass"
				})
			},
			handleCancel() {
				this.show = false
			},
			pubTask(index) {
				wx.vibrateShort();
				if (index == 0) {
					uni.navigateTo({
						url: "/pageHome/pubClassStyle"
					})
				} else {
					this.$api.post({
						url: '/yteachplan/chkPlan'
					}, {
						schoolid: this.currSchool.id
					}).then(res => {
						if (res.ispub == 'yes') {
							uni.navigateTo({
								url: '/pageHome/sjView'
							})
						} else {
							this.$refs.uToast.show({
								title: '未发布实践计划！\r\n请耐心等待~',
								type: 'warning',
								duration: '3000'
							})
						}
					})
				}
				this.show = false
			},
			getschooltrs() {
				this.$api.post({
					url: '/dteacher/getschooltrs'
				}, {
					schoolid: this.user.schoolId
				}).then(res => {
					this.invite_cnt = res.cnt;
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	.mains {
		width: 100%;
		height: 100%;
	}

	.content {
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.bar {
		display: flex;
		align-items: center;
		padding-left: 50rpx;
	}

	.ml50 {
		margin-left: 20rpx;
	}

	.flex-1 {
		flex: 1;
		text-align: center;
		height: 112rpx;
		line-height: 112rpx;
		font-size: 28rpx;
		background: #F8F9FC;
		color: #1C1C1C;
		font-weight: bold;
	}

	.pubbar {
		width: 100%;
		padding: 100rpx;
	}

	.title-top {
		padding-left: 76rpx;
		width: 100%;
		text-align: left;
		font-size: 28rpx;
		height: 128rpx;
		line-height: 128rpx;
		border-bottom: 2rpx solid #EEF4F8;
		color: #959AA5;
	}
</style>
